{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2023-12-03T02:11:34.266575700Z",
     "start_time": "2023-12-03T02:11:33.724349900Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "                title  author category secondary_category status  \\\n0                宿命之环  爱潜水的乌贼       玄幻               异世大陆     连载   \n1                 渊天尊      烽仙       玄幻               高武世界     连载   \n2     神话纪元，我进化成了恒星级巨兽   群玉山头见       玄幻               高武世界     连载   \n3                 乱世书      姬叉       玄幻               东方玄幻     连载   \n4                女侠且慢    关关公子       玄幻               东方玄幻     连载   \n...               ...     ...      ...                ...    ...   \n1465           娘子，看剑！     张悬河       仙侠               修真文明     连载   \n1466       长生修仙：从福修开始  宅到时间尽头       仙侠               修真文明     连载   \n1467  什么年代了，还穿越正经主神空间  不是有意错字     诸天无限                 无限     连载   \n1468   我，丁修，古龙武侠第一杀手！   那一抹绯红     诸天无限                 诸天     连载   \n1469      修仙：我只想进大宗门苟    锦鲤好运       仙侠               幻想修仙     连载   \n\n                                              introduce  month_ticket  \n0                         诡秘世界第二部。1368之年，七月之末，深红将从天而降。         103201  \n1      天地茫茫，仙道渺渺，九域中至高无上者，名曰‘天尊’。——ps：天才流！无系统！ps：已有完...         39919  \n2      苍穹之上，数千米长的鲲从城市上空飞过，无视漫天导弹轰炸。澳利洲，长达千米的灭世巨蟒摧毁城市...         33977  \n3      仗剑江湖载酒行，楚腰纤细掌中轻。少年肩扛长刀，腰间挂酒，大步前行，心中的江湖却隐约难见。乱...         33607  \n4      “女侠且慢，你可知我是什么人？”“知道，女帝身边的宠臣，反贼头目的相好，江湖名门的少主。脚...         24603  \n...                                                 ...           ...  \n1465   我承认娘子你很强。但假如，我是说假如，假如我以意念催动全部真元燃烧，以离仙九剑起手，不惜断...           692  \n1466   叶青玄意外穿越地玄界，无意中获得分身永恒龟，从此寿元无尽！更是意外得到地仙传承，拜入霸主级...           688  \n1467   本来是社畜的唐烎死了来到主神空间后，本以为自己的人生已经够抽象。没有想到这个主神空间更抽象...           688  \n1468   一朝穿越，古龙世界！人在江湖，身不由己！作为一个没怎么看过武侠小说的零零后，只能凭一点零散...           683  \n1469   “欢迎诸位小友加入缈瓦国大剑门！”林长安瞪直了眼，经历散修之苦的他，想加入大晋的天剑门混个...           679  \n\n[1470 rows x 7 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>title</th>\n      <th>author</th>\n      <th>category</th>\n      <th>secondary_category</th>\n      <th>status</th>\n      <th>introduce</th>\n      <th>month_ticket</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>宿命之环</td>\n      <td>爱潜水的乌贼</td>\n      <td>玄幻</td>\n      <td>异世大陆</td>\n      <td>连载</td>\n      <td>诡秘世界第二部。1368之年，七月之末，深红将从天而降。</td>\n      <td>103201</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>渊天尊</td>\n      <td>烽仙</td>\n      <td>玄幻</td>\n      <td>高武世界</td>\n      <td>连载</td>\n      <td>天地茫茫，仙道渺渺，九域中至高无上者，名曰‘天尊’。——ps：天才流！无系统！ps：已有完...</td>\n      <td>39919</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>神话纪元，我进化成了恒星级巨兽</td>\n      <td>群玉山头见</td>\n      <td>玄幻</td>\n      <td>高武世界</td>\n      <td>连载</td>\n      <td>苍穹之上，数千米长的鲲从城市上空飞过，无视漫天导弹轰炸。澳利洲，长达千米的灭世巨蟒摧毁城市...</td>\n      <td>33977</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>乱世书</td>\n      <td>姬叉</td>\n      <td>玄幻</td>\n      <td>东方玄幻</td>\n      <td>连载</td>\n      <td>仗剑江湖载酒行，楚腰纤细掌中轻。少年肩扛长刀，腰间挂酒，大步前行，心中的江湖却隐约难见。乱...</td>\n      <td>33607</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>女侠且慢</td>\n      <td>关关公子</td>\n      <td>玄幻</td>\n      <td>东方玄幻</td>\n      <td>连载</td>\n      <td>“女侠且慢，你可知我是什么人？”“知道，女帝身边的宠臣，反贼头目的相好，江湖名门的少主。脚...</td>\n      <td>24603</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>1465</th>\n      <td>娘子，看剑！</td>\n      <td>张悬河</td>\n      <td>仙侠</td>\n      <td>修真文明</td>\n      <td>连载</td>\n      <td>我承认娘子你很强。但假如，我是说假如，假如我以意念催动全部真元燃烧，以离仙九剑起手，不惜断...</td>\n      <td>692</td>\n    </tr>\n    <tr>\n      <th>1466</th>\n      <td>长生修仙：从福修开始</td>\n      <td>宅到时间尽头</td>\n      <td>仙侠</td>\n      <td>修真文明</td>\n      <td>连载</td>\n      <td>叶青玄意外穿越地玄界，无意中获得分身永恒龟，从此寿元无尽！更是意外得到地仙传承，拜入霸主级...</td>\n      <td>688</td>\n    </tr>\n    <tr>\n      <th>1467</th>\n      <td>什么年代了，还穿越正经主神空间</td>\n      <td>不是有意错字</td>\n      <td>诸天无限</td>\n      <td>无限</td>\n      <td>连载</td>\n      <td>本来是社畜的唐烎死了来到主神空间后，本以为自己的人生已经够抽象。没有想到这个主神空间更抽象...</td>\n      <td>688</td>\n    </tr>\n    <tr>\n      <th>1468</th>\n      <td>我，丁修，古龙武侠第一杀手！</td>\n      <td>那一抹绯红</td>\n      <td>诸天无限</td>\n      <td>诸天</td>\n      <td>连载</td>\n      <td>一朝穿越，古龙世界！人在江湖，身不由己！作为一个没怎么看过武侠小说的零零后，只能凭一点零散...</td>\n      <td>683</td>\n    </tr>\n    <tr>\n      <th>1469</th>\n      <td>修仙：我只想进大宗门苟</td>\n      <td>锦鲤好运</td>\n      <td>仙侠</td>\n      <td>幻想修仙</td>\n      <td>连载</td>\n      <td>“欢迎诸位小友加入缈瓦国大剑门！”林长安瞪直了眼，经历散修之苦的他，想加入大晋的天剑门混个...</td>\n      <td>679</td>\n    </tr>\n  </tbody>\n</table>\n<p>1470 rows × 7 columns</p>\n</div>"
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "df = pd.read_csv('../static/data/qi_dian_book.csv')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "data": {
      "text/plain": "{'name': ['赤心巡天',\n  '宿命之环',\n  '都重生了谁谈恋爱啊',\n  '不许没收我的人籍',\n  '深海余烬',\n  '逼我重生是吧',\n  '国民法医',\n  '唐人的餐桌',\n  '这游戏也太真实了',\n  '御兽之王'],\n 'value': [115974,\n  103201,\n  91330,\n  64934,\n  61405,\n  59807,\n  59311,\n  50516,\n  49748,\n  48938]}"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_ticket_top10 = df.sort_values('month_ticket', ascending=False).head(10)\n",
    "name = df_ticket_top10['title'].values.tolist()\n",
    "value = df_ticket_top10['month_ticket'].values.tolist()\n",
    "{\n",
    "    'name': name,\n",
    "    'value': value\n",
    "}"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-03T02:11:34.273699700Z",
     "start_time": "2023-12-03T02:11:34.263555400Z"
    }
   },
   "id": "a0b83fbafc386962"
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "data": {
      "text/plain": "[{'value': 110, 'name': '完本'},\n {'value': 1, 'name': '暂停'},\n {'value': 1359, 'name': '连载'}]"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_ratio_status = df.groupby('status').count()['title'].reset_index()\n",
    "ratio_status_data = [{'value': i[1], 'name': i[0]} for i in df_ratio_status.values]\n",
    "ratio_status_data"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-03T02:11:34.310054800Z",
     "start_time": "2023-12-03T02:11:34.276697900Z"
    }
   },
   "id": "388dfdc582458e6f"
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [],
   "source": [
    "category = df.groupby(['category']).count().index.tolist()\n",
    "category_data = [\n",
    "    {\n",
    "        'name': i,\n",
    "        'value': len(df[df['category'] == i]),\n",
    "        'children': [\n",
    "            {\n",
    "                'name': i+'-'+j[0],\n",
    "                'value': j[1]\n",
    "            } for j in df[df['category'] == i]\n",
    "            .groupby('secondary_category')\n",
    "            .count()['title']\n",
    "            .reset_index()\n",
    "            .values\n",
    "        ]\n",
    "    } for i in category\n",
    "]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-03T02:11:34.417014800Z",
     "start_time": "2023-12-03T02:11:34.294967Z"
    }
   },
   "id": "d97ef381cc8995fa"
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "outputs": [
    {
     "data": {
      "text/plain": "[{'value': 100, 'name': '全部'},\n {'value': 92.45, 'name': '连载'},\n {'value': 49.39, 'name': '月票>1000'},\n {'value': 7.14, 'name': '玄幻'},\n {'value': 4.01, 'name': '东方玄幻'}]"
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_status = df[df['status'] == '连载']\n",
    "df_month_ticket = df_status[df_status['month_ticket'] > 1000]\n",
    "df_category = df_month_ticket[df_month_ticket['category'] == '玄幻']\n",
    "df_secondary_category = df_category[df_category['secondary_category'] == '东方玄幻']\n",
    "[\n",
    "    {\n",
    "        'value':100,\n",
    "        'name':'全部'\n",
    "    },\n",
    "    {\n",
    "        'value':round(len(df_status)/len(df)*100,2),\n",
    "        'name':'连载'\n",
    "    },\n",
    "    {\n",
    "        'value':round(len(df_month_ticket)/len(df)*100,2),\n",
    "        'name':'月票>1000'\n",
    "    },\n",
    "    {\n",
    "        'value':round(len(df_category)/len(df)*100,2),\n",
    "        'name':'玄幻'\n",
    "    },\n",
    "    {\n",
    "        'value':round(len(df_secondary_category)/len(df)*100,2),\n",
    "        'name':'东方玄幻'\n",
    "    }\n",
    "]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-03T02:37:30.697080400Z",
     "start_time": "2023-12-03T02:37:30.688020300Z"
    }
   },
   "id": "6851e582d071bcb6"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
